﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;

using Stitch.Database;

namespace Data.GameData.Entities
{
    public class EBaseObject
    {
        private static DBConnection dbConnection;
        protected static DBResult databaseResult;
        protected DBRow values;

        public EBaseObject()
        {
            DbConnect();
        }

        public DBRow Values
        {
            get { return values; }
            internal set { values = value; }
        }

        internal static void RunNonSelectSQL(string sqlString)
        {
            if (dbConnection == null)
                DbConnect();

            dbConnection.NonSelectQuery(sqlString);
        }

        internal static void RunSQL(string sqlString)
        {
            if (dbConnection == null)
                DbConnect();

            databaseResult = dbConnection.SelectQuery(sqlString);
        }

        internal static void RunSQL(string sqlString, bool selecting)
        {
            if (selecting)
                RunSQL(sqlString);
            else
                RunNonSelectSQL(sqlString);
        }

        private static void DbConnect()
        {
            string dbServer = ConfigurationSettings.AppSettings["dbServer"];
            string database = ConfigurationSettings.AppSettings["database"];
            string username = ConfigurationSettings.AppSettings["username"];
            string password = ConfigurationSettings.AppSettings["password"];

            dbConnection = new DBConnection(DatabaseType.MSSQL, dbServer, username, password, database);
        }
    }
}
